package com.springboot.middleware.middleware_redisson.server.rabbitmq;

import com.springboot.middleware.middleware_redisson.server.dto.DeadDto;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * 死信队列基本模型 - 消费者
 */
@Component
public class MqDelayQueueConsumer {
    private static final Logger log = LoggerFactory.getLogger(MqDelayQueueConsumer.class);

    @Autowired
    private RedissonClient redissonClient;

    /**
     * 监听消费者真正队列的消息
     *
     * @param dto dto
     */
    @RabbitListener(queues = {"middleware.redisson.real.queue"})
    public void consumeMsg(@Payload DeadDto dto) {
        try {
            log.info("RabbitMQ死信队列消息模型-消费者-监听消费者真正队列中的消息:{}", dto);
            // TODO: 2022/1/26 这里执行真正的业务逻辑 
        } catch (Exception e) {
            log.error("RabbitMQ死信队列消息模型-消费者-监听消费者真正队列中的消息-发生异常: {}", dto, e.fillInStackTrace());
        }
    }
}
